import * as TYPES from './mutation-types'
import {getCustomer} from '../api/getData'
export const setUser = ({
  commit
}, user) => {
  if (user) {
    commit(TYPES.SET_LOGIN, true)
  } else {
    commit(TYPES.SET_LOGIN, false)
  }
  commit(TYPES.SET_CURRENTUSER, user)
}
export const setCity = async ({
  commit
}, city) => {
  commit(TYPES.SET_CITY, city.id)
  commit(TYPES.SET_CITYNAME, city.name)

  let phone = await getCustomer(city.id)
  if(phone.data.list.length == 0) {
    commit(TYPES.SET_SERVICE_PHONE, '00000000000')
    return
  }
  commit(TYPES.SET_SERVICE_PHONE, phone.data.list[0].number)
  commit(TYPES.SET_QQNUM, phone.data.list[0].qq)
}
export const setFlag = ({
  commit
}, resetFlag) => {
  commit(TYPES.SET_RESETFLAG, resetFlag)
}
export const setSideShowFn = ({
  commit
}, showBool) => {

  commit(TYPES.SET_SIDESHOW, showBool)
}
export const setSupplyflag = ({
  commit
}, needSupplyInfo) => {
  commit(TYPES.SET_SUPPLYFLAG, needSupplyInfo)
}
export const setNeedPayBool = ({
  commit
}, NeedPayBool) => {
  commit(TYPES.SET_NEEDPAY, NeedPayBool)
}
export const setDialogClose = ({
  commit
}, dialogClose) => {
  commit(TYPES.SET_DIALOGCLOSE, dialogClose)
}

export const setTradeRecord = ({
  commit
}, tradeRecord) => {
  commit(TYPES.SET_TRADERECORD, tradeRecord)
}

export const setFirstPayBool = ({
  commit
}, firstPayBool) => {
  commit(TYPES.SET_FIRSTPAYBOOL, firstPayBool)
}
export const setSeivicePhone = async ({
  commit
}, id) => {
  let phone = await getCustomer(id)
  if( phone.data.list.length == 0) {
    commit(TYPES.SET_SERVICE_PHONE, '00000000000')
    return
  }
  commit(TYPES.SET_SERVICE_PHONE, phone.data.list[0].number)
  commit(TYPES.SET_QQNUM, phone.data.list[0].qq)
}
export const setResultCourse = ({
  commit
}, result) => {
  commit(TYPES.SET_RESULT_COURSE, result)
}

export const setShowEmailBtn = ({
  commit
}, ShowEmailBtnBool) => {
  commit(TYPES.SET_SHOW_EMAIL_BTN_BOOL, ShowEmailBtnBool)
}

export const setFreeTime = ({commit}, freeTime) => {
  commit(TYPES.SET_FREE_TIME, freeTime)
}
export const setUnreadNumber = ({commit}, unreadNumber) => {
  commit(TYPES.SET_UNREAD_NUMBER, unreadNumber)
}
export const setUnreadlsNumber = ({commit}, unreadlsNumber) => {
  commit(TYPES.SET_UNREADLS_NUMBER, unreadlsNumber)
}